package com.dwxt.community.controller;

import com.dwxt.common.annotation.*;
import com.dwxt.common.base.*;
import com.dwxt.community.entity.*;
import com.dwxt.community.service.*;
import com.github.pagehelper.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/*******客服*******/
@RequestMapping("/cms/customer")
@RestController
public class CustomerController {

    @Value("${customer.service.phone}")
    private String phone;

    @Autowired
    private CustomerService customerService;

    /**
     * showdoc
     * @catalog 社区/客服
     * @title 获取客服电话
     * @description  获取客服电话
     * @url /cms/customer/selectCustomerPhone
     * @return {"status":200,"msg":"SUCCESS","data":"15123058497"}
     */
    @RequestMapping("/selectCustomerPhone")
    public BaseResult selectCustomerPhone(){
        return BaseResult.ok(phone);
    }

    /**
     * showdoc
     * @catalog 社区/客服
     * @title 提交问题
     * @description  提交问题
     * @param phone 必选 int 电话号码
     * @param problem 必选 string 问题
     * @url /cms/customer/commitProblem
     * @return {"status":200,"msg":"SUCCESS","data":null}
     */
    @RequestMapping("/commitProblem")
    @ValidateGroup(fileds ={
            @ValidateFiled(index = 0,filedName = "phone",regStr = "^1[3|4|5|6|7|8|9][0-9]\\d{4,8}$"),
            @ValidateFiled(index = 0,filedName = "problem",notNull = true),
    })
    public BaseResult commitProblem(CustomerProblem customerProblem){
        customerService.commitProblem(customerProblem);
        return BaseResult.ok();
    }

    /**
     * showdoc
     * @catalog 社区/客服
     * @title 问题记录分页查询
     * @description  问题记录分页查询
     * @param pageNum 必选 int 页码(1开始)
     * @param pageSize 必选 int 一页数量
     * @url /cms/customer/selectProblemPage
     * @return {"status":200,"msg":"SUCCESS","data":{"total":1,"list":[{"id":1,"phone":"15123058497","userId":"158502014539731","createTime":1586961050000,"problem":null}],"pageNum":10,"pageSize":0,"size":1,"startRow":1,"endRow":1,"pages":0,"prePage":0,"nextPage":0,"isFirstPage":false,"isLastPage":true,"hasPreviousPage":true,"hasNextPage":false,"navigatePages":8,"navigatepageNums":[],"navigateFirstPage":0,"navigateLastPage":0}}
     */
    @RequestMapping("/selectProblemPage")
    @ValidateGroup(fileds ={
            @ValidateFiled(index = 0,notNull = true),
            @ValidateFiled(index = 1,notNull = true),
    })
    public BaseResult selectProblemPage(Integer pageNum,Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<CustomerProblem> problems= customerService.selectProblemList();
        PageInfo<CustomerProblem> pageInfo=new PageInfo<>(problems);
        return BaseResult.ok(pageInfo);
    }

    /**
     * 查询某个会话的回复详情
     * @param conversationId
     * @return
     */
    @RequestMapping("/selectProblemDetail")
    @ValidateGroup(fileds ={
            @ValidateFiled(index = 0,notNull = true),
    })
    public BaseResult selectProblemDetail(String conversationId){
        List<CustomerProblem> customerProblems=customerService.selectProblemDetail(conversationId);
        return BaseResult.ok(customerProblems);
    }


    /**
     * showdoc
     * @catalog 社区/客服
     * @title 删除问题
     * @description  删除问题
     * @param id 必选 int id
     * @url /cms/customer/delete
     * @return {"status":200,"msg":"SUCCESS","data":null}
     */
    @RequestMapping("/delete")
    @ValidateGroup(fileds ={
            @ValidateFiled(index = 0,notNull = true),
    })
    public BaseResult delete(Integer id){
        customerService.delete(id);
        return BaseResult.ok();
    }
}
